<% // Copyright 2008 Carnegie Mellon University
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//  
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, 
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License. %>

<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page pageEncoding="UTF-8" %>
<%@page import="edu.cmu.lti.sepia.data.resource.ResourceManager"%>
<%@page import="java.io.InputStreamReader"%>

<%@page import="java.util.Enumeration"%>
<%@page import="java.util.Properties"%>
<%@page import="java.util.Map"%><html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta content="no-cache" http-equiv="Cache-Control">
</head>
<body>
<%{ %>
Application, Session, RequestXXX Parameter, Get/Post Parameter, HeaderParameter, Attributes, System properties, System env.
<hr>
Application Parameters:
<table border=1>
<tr><td><strong>key</strong></td><td><strong>value</strong></td></tr>
<% 
for (Enumeration<String> e = application.getAttributeNames(); e.hasMoreElements();) {
    String key = (String) e.nextElement();
	if ( application.getAttribute(key).getClass().equals(String.class) ) {
    	out.println( "<tr><td>"+key+"</td><td>"+(String)application.getAttribute(key)+"&nbsp;</td></tr>" );
	}
	if ( !application.getAttribute(key).getClass().equals(String.class) ) {
    	out.println( "<tr><td>"+key+"</td><td>"+application.getAttribute(key)+"&nbsp;</td></tr>" );
	}
}
%>
</table>
<br>
Session Parameters:
<table border=1>
<tr><td><strong>key</strong></td><td><strong>value</strong></td></tr>
<% 
for (Enumeration<String> e = session.getAttributeNames(); e.hasMoreElements();) {
    String key = (String) e.nextElement();
    Object obj = session.getAttribute(key);
	if ( obj.getClass().equals(String.class) ) {
    	out.println( "<tr><td>"+key+"</td><td>"+(String)obj+"&nbsp;</td></tr>" );
	}
	if ( !obj.getClass().equals(String.class) ) {
    	out.println( "<tr><td>"+key+"</td><td>"+obj+"&nbsp;</td></tr>" );
	}
}
%>
</table>
<br>
RequestXXX Parameters:
<table border=1>
<tr><td><strong>key</strong></td><td><strong>value</strong></td></tr>
<% 
out.println("<tr><td>authType</td><td>"+request.getAuthType()+"<tr>");
out.println("<tr><td>characterEncoding</td><td>"+request.getCharacterEncoding()+"<tr>");
out.println("<tr><td>contentLength</td><td>"+request.getContentLength()+"<tr>");
out.println("<tr><td>contentType</td><td>"+request.getContentType()+"<tr>");
out.println("<tr><td>contextPath</td><td>"+request.getContextPath()+"<tr>");
out.println("<tr><td>method</td><td>"+request.getMethod()+"<tr>");
out.println("<tr><td>pathInfo</td><td>"+request.getPathInfo()+"<tr>");
out.println("<tr><td>pathTranslated</td><td>"+request.getPathTranslated()+"<tr>");
out.println("<tr><td>protocol</td><td>"+request.getProtocol()+"<tr>");
out.println("<tr><td>queryString</td><td>"+request.getQueryString()+"<tr>");
out.println("<tr><td>remoteAddr</td><td>"+request.getRemoteAddr()+"<tr>");
out.println("<tr><td>remoteHost</td><td>"+request.getRemoteHost()+"<tr>");
out.println("<tr><td>remoteUser</td><td>"+request.getRemoteUser()+"<tr>");
out.println("<tr><td>requestedSessionId</td><td>"+request.getRequestedSessionId()+"<tr>");
out.println("<tr><td>requestURI</td><td>"+request.getRequestURI()+"<tr>");
out.println("<tr><td>scheme</td><td>"+request.getScheme()+"<tr>");
out.println("<tr><td>serverName</td><td>"+request.getServerName()+"<tr>");
out.println("<tr><td>serverPort</td><td>"+request.getServerPort()+"<tr>");
out.println("<tr><td>servletPath</td><td>"+request.getServletPath()+"<tr>");
%>
</table>
<br>
Get/Post Parameters:
<table border=1>
<tr><td><strong>key</strong></td><td><strong>value</strong></td></tr>
<% 
for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) {
    String key = (String) e.nextElement();
    Object obj = request.getParameter(key);
	if ( obj.getClass().equals(String.class) ) {
    	out.println( "<tr><td>"+key+"</td><td>"+(String)obj+"&nbsp;</td></tr>" );
	}
	if ( !obj.getClass().equals(String.class) ) {
    	out.println( "<tr><td>"+key+"</td><td>"+obj+"&nbsp;</td></tr>" );
	}
}
%>
</table>
<br>
Header Parameters:
<table border=1>
<tr><td><strong>key</strong></td><td><strong>value</strong></td></tr>
<% 

for (Enumeration<String> e = request.getHeaderNames(); e.hasMoreElements();) {
    String key = (String) e.nextElement();
    Object obj = request.getHeader(key);
	if ( obj.getClass().equals(String.class) ) {
    	out.println( "<tr><td>"+key+"</td><td>"+(String)obj+"&nbsp;</td></tr>" );
	}
	if ( !obj.getClass().equals(String.class) ) {
    	out.println( "<tr><td>"+key+"</td><td>"+obj+"&nbsp;</td></tr>" );
	}
}
%>
</table>
<br>
Attributes:
<table border=1>
<tr><td><strong>key</strong></td><td><strong>value</strong></td></tr>
<% 
for (Enumeration<String> e = request.getAttributeNames(); e.hasMoreElements();) {
    String key = (String) e.nextElement();
    Object obj = request.getAttribute(key);
	if ( obj.getClass().equals(String.class) ) {
    	out.println( "<tr><td>"+key+"</td><td>"+(String)obj+"&nbsp;</td></tr>" );
	}
	if ( !obj.getClass().equals(String.class) ) {
    	out.println( "<tr><td>"+key+"</td><td>"+obj+"&nbsp;</td></tr>" );
	}
}
%>
</table>
<br>
System Properties:
<table border=1>
<tr><td><strong>key</strong></td><td><strong>value</strong></td></tr>
<% 
Properties properties = System.getProperties();
for ( Object obj : properties.keySet() ) {
	String key = (String)obj;
	out.println( "<tr><td>"+key+"</td><td>"+properties.getProperty(key)+"&nbsp;</td></tr>" );
}
%>
</table>
<br>
System Env:
<table border=1>
<tr><td><strong>key</strong></td><td><strong>value</strong></td></tr>
<% 
Map<String,String> map = System.getenv();
for ( String key : map.keySet() ) {
	out.println( "<tr><td>"+key+"</td><td>"+map.get(key)+"&nbsp;</td></tr>" );
}
%>
</table>

<hr>

<code><pre>
<%
String lang2 = (String)session.getAttribute("displayLang");

out.println("(String)session.getAttribute(\"language\") = "+(String)session.getAttribute("language"));
out.println("(String)session.getAttribute(\"srcLang\") = "+(String)session.getAttribute("srcLang"));
out.println("(String)session.getAttribute(\"trgLang\") = "+(String)session.getAttribute("trgLang"));
out.println("(String)session.getAttribute(\"displayLang\") = "+(String)session.getAttribute("displayLang"));

String root = application.getRealPath("WEB-INF/classes/MessageResources_"+lang2+".properties");
out.println( "application.getRealPath(\"WEB-INF/classes/MessageResources_"+lang2+".properties\") = "+application.getRealPath("WEB-INF/classes/MessageResources_"+lang2+".properties") );
out.println( "application.getResourcePaths(\"/WEB-INF/\") = "+application.getResourcePaths("/WEB-INF/") );
out.println( "application.getResource(\"/WEB-INF/\") = "+application.getResource("/WEB-INF/") );

String prop = "/WEB-INF/classes/sepia.properties";
out.println( "application.getRealPath(\""+prop+"\") = "+application.getRealPath(prop) );
out.println( "application.getResourcePaths(\""+prop+"\") = "+application.getResourcePaths(prop) );
out.println( "application.getResource(\""+prop+"\") = "+application.getResource(prop) );

%>
<%= new java.io.File(".").getAbsolutePath() %>
<% ResourceManager.init(); %>
<%= "(String)session.getAttribute(\"language\") = "+lang2 %>

<%= request.getParameterMap() %><br />

<%
try {
java.lang.ClassLoader cl = java.lang.Thread.currentThread().getContextClassLoader();
/* String path = ResourceManager.realRoot + java.io.File.separatorChar +
"WEB-INF"+java.io.File.separatorChar+
"classes"+java.io.File.separatorChar+
"resources"+java.io.File.separatorChar+
"MessageResources_"+lang2+".properties";
java.io.File f = new java.io.File( path );
out.println("-> "+f.getAbsolutePath());
out.println("-> "+f.exists());
 
java.io.InputStream ff = new java.io.FileInputStream(f.getAbsoluteFile());
java.util.Properties p = new java.util.Properties();

out.println( "is==null -> "+(ff==null) );

p.load(ff);

out.println("keyset = "+p.keySet());

for ( Object o : p.keySet() ) {
	String key = o.toString();
	out.println( key+"&nbsp;:&nbsp;"+ p.getProperty(key));
}
*/

} catch ( Exception e ) {
	out.println("e.printStackTrace();");
	e.printStackTrace(new java.io.PrintWriter(out));
	out.println("e.getMessage()");
	out.println(e.getMessage());
	out.flush();
}
%>

<%} %>
</pre>
</code>
</body>
</html>
